import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.Statement;

public class DBConnector {
	Connection con = null;
	Statement stmt = null;
	ResultSet rs = null;

	static {
		try {
			Class.forName("com.mysql.jdbc.Driver");
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	void execute() {
		try {
			con = DriverManager.getConnection("jdbc:mysql://IP:3306/DBName",
					"uid", "pwd");
			stmt = con.createStatement();
			rs = stmt.executeQuery("select * from emp");
			if (rs != null) {
				while (rs.next()) {
					System.out.println(rs.getString("emp_id"));
					System.out.println(rs.getString(1));
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (con != null) {
				try {
					con.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
			if (stmt != null)
				try {
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			if (rs != null) {
				try {
					rs.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
}